package com.ruoyi.house_sale.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.house_sale.domain.Bank;
import com.ruoyi.house_sale.service.IBankService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.BankCompany;
import com.ruoyi.house_sale.service.IBankCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
/**
 * 公司银行账户Controller
 * 
 * @author ruoyi
 * @date 2022-03-30
 */
@RestController
@RequestMapping("/house_sale/BankCompany")
public class BankCompanyController extends BaseController
{
    @Autowired
    private IBankCompanyService bankCompanyService;
    @Autowired
    private IBankService bankService;

    /**
     * 查询公司银行账户列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:BankCompany:list')")
    @GetMapping("/list")
    public Map list(BankCompany bankCompany)
    {
        Map map =new HashMap<>();
        startPage();
        List<BankCompany> list = bankCompanyService.selectBankCompanyList(bankCompany);
        map.put("bankCompanyList",list);
        List<Bank> list2 = bankService.selectBankList(null);
        map.put("bankList",list2);
        return map;
    }

    /**
     * 导出公司银行账户列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:BankCompany:export')")
    @Log(title = "公司银行账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BankCompany bankCompany)
    {
        List<BankCompany> list = bankCompanyService.selectBankCompanyList(bankCompany);
        ExcelUtil<BankCompany> util = new ExcelUtil<BankCompany>(BankCompany.class);
        util.exportExcel(response, list, "公司银行账户数据");
    }

    /**
     * 获取公司银行账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:BankCompany:query')")
    @GetMapping(value = "/{bankaccount}")
    public AjaxResult getInfo(@PathVariable("bankaccount") String bankaccount)
    {
        return AjaxResult.success(bankCompanyService.selectBankCompanyByBankaccount(bankaccount));
    }

    /**
     * 新增公司银行账户
     */
    @PreAuthorize("@ss.hasPermi('house_sale:BankCompany:add')")
    @Log(title = "公司银行账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BankCompany bankCompany)
    {
        return toAjax(bankCompanyService.insertBankCompany(bankCompany));
    }

    /**
     * 修改公司银行账户
     */
    @PreAuthorize("@ss.hasPermi('house_sale:BankCompany:edit')")
    @Log(title = "公司银行账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BankCompany bankCompany)
    {
        return toAjax(bankCompanyService.updateBankCompany(bankCompany));
    }

    /**
     * 删除公司银行账户
     */
    @PreAuthorize("@ss.hasPermi('house_sale:BankCompany:remove')")
    @Log(title = "公司银行账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bankaccounts}")
    public AjaxResult remove(@PathVariable String[] bankaccounts)
    {
        return toAjax(bankCompanyService.deleteBankCompanyByBankaccounts(bankaccounts));
    }
}
